<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { ChallengeApi } from '@/api/controller'
  import { ToastSuccess, ToastWarning, Toastloading } from '@/utils/public';
  import updateForm from './updateForm.vue';
  import { ElMessageBox } from 'element-plus';
  import xmImage from '@/components/xmImage/index.vue';
  const updateFormRef = ref()
  const action = reactive({
    list:[] as Array<any>,
    SessionList:[] as Array<any>
  })
  const listQuery = reactive({
    game_id:'',
    item_type: ''
  })
  const options = [
    {type:1,text:'礼物'},
    {type:2,text:'技能'}
  ]
  const typeFont = (type:number=0)=>{
    if(type == 0) return '否'
    if(type == 1) return '是'
  }
  const handleSerach = ()=>{
    getList()
  }
  const handleUpdate = (row:any = {})=>{
    updateFormRef.value.openDialog(row)
  }
  const getSession = async()=>{
    const res = await ChallengeApi.gameSwitch()
    const { data } = res
    action.SessionList = data
    getList()
  }
  const getList = async()=>{
    const loading = Toastloading()
    const res = await ChallengeApi.poolList(listQuery)
    const { data=[] } = res || {}
    action.list = data
    loading.close()
    action.list = data
  }
  onMounted(() => {
    getSession()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">游戏类型：</div>
          <el-select v-model="listQuery.game_id" clearable placeholder="请选择类型">
            <el-option
              v-for="item in action.SessionList"
              :label="item.game_name"
              :value="item.game_id"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">游戏类型：</div>
          <el-select v-model="listQuery.item_type" clearable placeholder="请选择类型">
            <el-option
              v-for="item in options"
              :label="item.text"
              :value="item.type"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach()">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="80" prop="id" label="人物id" />
      <el-table-column sortable width="120" prop="sort" label="人物顺序" />
      <el-table-column min-width="120" prop="item_name" label="人物名称" />
      <el-table-column width="130" prop="item_img" label="人物图标">
        <template #default="scope">
          <xmImage :src="scope.row.item_img" :list="[scope.row.item_img]" />
        </template>
      </el-table-column>
      <el-table-column min-width="120" prop="gift_id" label="奖励礼物名称id" />
      <el-table-column min-width="120" prop="giftName" label="奖励礼物名称" />
      <el-table-column min-width="120" prop="reward_jd_num" label="奖励金豆数" />
      <el-table-column min-width="120" prop="base_rate" label="基础概率">
        <template #default="scope">{{ scope.row.base_rate / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="low_rate" label="低回概率">
        <template #default="scope">{{ scope.row.low_rate / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="high_rate" label="高回概率">
        <template #default="scope">{{ scope.row.high_rate / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="new_protect_rate" label="新人保护概率">
        <template #default="scope">{{ scope.row.new_protect_rate / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="day_rate_1" label="每日保护概率1">
        <template #default="scope">{{ scope.row.day_rate_1 / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="day_rate_2" label="每日保护概率2">
        <template #default="scope">{{ scope.row.day_rate_2 / 100 }}%</template>
      </el-table-column>
      <el-table-column min-width="120" prop="if_rank" label="上榜排行状态">
        <template #default="scope">{{ typeFont(scope.row.if_rank) }}</template>
      </el-table-column>
      <el-table-column min-width="120" prop="if_screen" label="飘屏状态">
        <template #default="scope">{{ typeFont(scope.row.if_screen) }}</template>
      </el-table-column>
      <el-table-column min-width="120" prop="if_notice" label="公告展示状态">
        <template #default="scope">{{ typeFont(scope.row.if_notice) }}</template>
      </el-table-column>
      <el-table-column width="120" fixed=right label="操作">
        <template #default="scope">
          <el-button type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <updateForm ref="updateFormRef" @update-list="getList" />
  </div>
</template>

<style lang='scss' scoped>
  
</style>